﻿@using SlamDunk.CMS.Model
@using SlamDunk.CMS.Model.DataModel
@model SlamDunk.CMS.Model.ViewModel.PhotoView

@{
    ViewBag.Title = "添加图片信息";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section header{
    <script type="text/javascript" src="~/SwfUpload/swfupload.js"></script>
    <script type="text/javascript" src="~/SwfUpload/handlers.js"></script>
    <script type="text/javascript">
        var swfu;       //定义上传图片控件
        $(function () {
            //初始化异步上传图片控件
            swfu = new SWFUpload({
                // Backend Settings
                upload_url: "/Admin/Article/UploadImage",          //用户上传文件的处理程序
                post_params: {
                    "ASPSESSID": "@Session.SessionID"
                },

                // File Upload Settings
                file_size_limit: "2 MB",
                file_types: "*.jpg;*.gif;*.png;*.bmp",
                file_types_description: "JPG Images",
                file_upload_limit: 0,    // Zero means unlimited

                // Event Handler Settings - these functions as defined in Handlers.js
                // The handlers are not part of SWFUpload but are part of my website and control how
                // my website reacts to the SWFUpload events.
                swfupload_preload_handler: preLoad,
                swfupload_load_failed_handler: loadFailed,
                file_queue_error_handler: fileQueueError,
                file_dialog_complete_handler: fileDialogComplete,
                upload_progress_handler: uploadProgress,
                upload_error_handler: uploadError,
                upload_success_handler: showMessage,
                upload_complete_handler: uploadComplete,

                // Button settings
                button_image_url: '@Url.Content("~/SwfUpload/images/XPButtonNoText_160x22.png")',
                button_placeholder_id: "spanButtonPlaceholder",
                button_width: 160,
                button_height: 22,
                button_text: '<span class="button">请选择图片 <span class="buttonSmall">(2MB Max)</span></span>',
                button_text_style: '.button { font: 14px "微软雅黑"; } .buttonSmall { font: 14px; }',
                button_text_top_padding: 1,
                button_text_left_padding: 5,

                // Flash Settings
                flash_url: '@Url.Content("~/SwfUpload/swfupload.swf")',	                // Relative to this file

                flash9_url: '@Url.Content("~/SwfUpload/swfupload_FP9.swf")',	    // Relative to this file

                custom_settings: {
                    upload_target: "divFileProgressContainer"
                },

                // Debug Settings
                debug: false
            });
        });
        //提交表单完成后执行方法
        function addFinished(jsonData) {
            if (jsonData.Status == '1') {
                window.top.window.$.messager.alert('OK', jsonData.Message);        //主窗口弹出消息提示
                $.globalParas.updateDataGridInTab();                                              //清除选中，刷新表格
                $.globalParas.closeComWindow();                                                    //关闭弹出窗口
            } else {
                window.top.window.$.messager.alert('Error', jsonData.Message);      //主窗口弹出消息提示
            }
        }

        /// <summary>
        /// 上传图片成功后执行的方法
        /// </summary>
        /// <param name="file"></param>
        /// <param name="serverData">从服务端返回的数据</param>
        function showMessage(file, serverData) {
            var data = serverData.split(':');
            if (data[0] == 'OK') {
                swfu.destroy();
                $('#txtImagePath').val(data[1]);
                $('#txtThumbPath').val(data[2]);
            } else {
                alert(data[1]);
            }
        }
    </script>
    <style type="text/css">
        #dvIframe {
            margin-top: 15px;
            width: 400px;
            float: left;
        }

        #dvDep {
            margin-top: 18px;
            float: left;
        }

        #tblAdd {
            width: 500px;
            margin: 5px 0 0 40px;
            text-align: right;
        }

            #tblAdd td input, textarea {
                width: 230px;
            }

        textarea {
            height: 120px;
        }

        .tdValidate {
            text-align: right;
            color: #ff0000;
        }

        .tdContent {
            text-align: left;
        }
    </style>
}

@using (Ajax.BeginForm("AddConfirm", "Photo", new AjaxOptions { OnSuccess = "addFinished" }, new { id = "frmAdd" }))
{
    <div id="dvIframe">
        <table id="tblAdd">
            <tr>
                <td class="tdTitle">@Html.LabelFor(x => x.AlbumId)：</td>
                <td class="tdContent">
                    <select name="AlbumId">
                        @foreach (PhotoAlbum album in ViewBag.AlbumList)
                        {
                            <option value="@album.Id">@album.AlbumName</option>
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td class="tdValidate" colspan="2">@Html.ValidationMessageFor(x => x.AlbumId)</td>
            </tr>
            <tr>
                <td class="tdTitle">@Html.LabelFor(x => x.PhotoName)：</td>
                <td class="tdContent">@Html.TextBoxFor(x => x.PhotoName, new { id = "txtPhotoName" })</td>
            </tr>
            <tr>
                <td class="tdValidate" colspan="2">@Html.ValidationMessageFor(x => x.PhotoName)</td>
            </tr>
            <tr>
                <td class="tdTitle">@Html.LabelFor(x => x.Url)：</td>
                <td class="tdContent">@Html.TextBoxFor(x => x.Url, new { id = "txtUrl" })</td>
            </tr>
            <tr>
                <td class="tdValidate" colspan="2">@Html.ValidationMessageFor(x => x.Url)</td>
            </tr>
            <tr>
                <td class="tdTitle">@Html.LabelFor(x => x.Sort)：</td>
                <td class="tdContent">@Html.TextBoxFor(x => x.Sort, new { id = "txtSort" })</td>
            </tr>
            <tr>
                <td class="tdValidate" colspan="2">@Html.ValidationMessageFor(x => x.Sort)</td>
            </tr>
            <tr>
                <td class="tdTitle">@Html.LabelFor(x => x.ImagePath)：</td>
                <td class="tdContent">
                    @Html.TextBoxFor(x => x.ImagePath, new { id = "txtImagePath" })
                    <input type="hidden" id="txtThumbPath" name="ThumbPath" value="" />
                    <span id="spanButtonPlaceholder"></span>
                </td>
            </tr>
            <tr>
                <td class="tdValidate" colspan="2">@Html.ValidationMessageFor(x => x.ImagePath)</td>
            </tr>
            <tr>
                <td class="tdTitle">@Html.LabelFor(x => x.Description)：</td>
                <td class="tdContent">@Html.TextAreaFor(x => x.Description, new { id = "txtDescription" })</td>
            </tr>
            <tr>
                <td class="tdValidate" colspan="2">@Html.ValidationMessageFor(x => x.Description)</td>
            </tr>
            <tr>
                <td></td>
                <td class="tdContent">
                    <a href="#" onclick="javascript: $('#frmAdd').submit();" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定</a>
                    <a href="#" onclick="javascript: $.globalParas.closeComWindow();" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a>
                </td>
            </tr>
        </table>
    </div>
}